#include "pthreadpool.h"
void* pthreadfunc(void *arg)
{
    printf("%lu 号woker 已就绪\n", pthread_self()%1000);
    share_t *pshare = (share_t *)arg;
    while(1)
    {
        pthread_mutex_lock(&pshare->mutex);
        while(pshare->exitflag ==0 && pshare->queue.qsize <=0)
        {
            pthread_cond_wait(&pshare->cond,&pshare->mutex);
        }
        if(pshare->exitflag==1)
        {
            printf("我是子线程 %lu号worker\n",pthread_self()%1000);
            pthread_mutex_unlock(&pshare->mutex);
            pthread_exit(NULL);
        }
        int val=dequeue(&pshare->queue);
        printf("%lu 号woker正在执行 %d的任务\n",pthread_self()%1000,val);
        pthread_mutex_unlock(&pshare->mutex);
        transfile(val,pshare->filename);
        close(val);
    }
    return NULL;
}
int makeworker(share_t * share)
{
    for(int i=0;i<share->ptidarr.workernum;i++)
    {
        pthread_create(&share->ptidarr.tidarr[i],NULL,pthreadfunc,share);
    }
    return 0;
}
